package com.atguigu.oss.service.impl;

import com.atguigu.oss.service.VideoService;
import com.atguigu.servicebase.exceptionHandler.GuliException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

@Service
@Slf4j
public class VideoServiceImpl implements VideoService {
    @Override
    public void removeMoreVideo(String video,List<String> videoIdList) {
        try {
            //videoIdList值转换成 1,2,3
//            String videoIds = StringUtils.join(videoIdList.toArray(), ",");
            for (String str : videoIdList) {
                File file = new File(System.getProperty("user.dir") + "\\ossdata\\" + video + "\\" + str);
                if(!file.exists()){
                   log.error("文件不存在: "+str);
                }
                file.delete();
            }

        }catch (Exception e){
            e.printStackTrace();
            throw new GuliException(20001,"删除视频失败");
        }

    }
}
